# init
[ -n "$CONFIG_FLAG" ] && return 0

######################################################

# config variable

# device name, eg. /dev/sdX
SD=${SD:-""}
partition_modes=(USB_MBR USB_GPT USB_Hybrid USB_Hybrid_HD MBR GPT BtrFS)
PARTITION_MODE=${PARTITION_MODE:-""}
virtual_machines=(None Hyper-V Virtual-Box VMWare)
VIRTUAL_MACHINE=${VIRTUAL_MACHINE:-""}
HD_NTFS_SIZE=${HD_NTFS_SIZE:-""} # only used by "USB_Hybrid_HD"

VIRTUAL_MACHINE_RESOLUTION_RATIO="1300x600"

FS=/mnt/f
ROOT=/mnt/r

#######################################################

until [ -w "$SD" ]
do
    echo -n "SD:"
    read SD
done

if [ -z "$PARTITION_MODE" ]
then
    echo_info "PARTITION_MODE:"
    select PARTITION_MODE in ${partition_modes[@]}
    do
        if [ -n "$PARTITION_MODE" ]
        then
            break
        fi
    done
fi

if [ -z "$VIRTUAL_MACHINE" ]
then
    echo_info "VIRTUAL_MACHINE:"
    select VIRTUAL_MACHINE in ${virtual_machines[@]}
    do
        if [ -n "$VIRTUAL_MACHINE" ]
        then
            break
        fi
    done
fi

SUBDIR=""

case $PARTITION_MODE in
    USB_MBR)
        SUBDIR="usb_mbr"
        ;;
    USB_GPT)
        SUBDIR="usb_gpt"
        ;;
    USB_Hybrid)
        SUBDIR="usb_hybrid"
        ;;
    USB_Hybrid_HD)
        SUBDIR="usb_hybrid_hd"
        until [ -n "$HD_NTFS_SIZE" ]
        do
            echo -n "ntfs size(MiB):"
            read HD_NTFS_SIZE
        done
        ;;
    MBR)
        SUBDIR="mbr"
        ;;
    GPT)
        SUBDIR="gpt"
        ;;
    BtrFS)
        SUBDIR="btrfs"
        ;;
    *)
        echo_err "unknown partition mode"
        return 1
        ;;
esac

echo_info "device: $SD"
echo_info "partition mode: $PARTITION_MODE"
echo_info "virtual machine: $VIRTUAL_MACHINE"
case $PARTITION_MODE in
    USB_Hybrid_HD)
        echo_info "ntfs size: $HD_NTFS_SIZE MiB"
        ;;
esac

CONFIG_FLAG="flag"

return 0

# vim: ft=sh
